import {defineConfig} from "vite";
import uni from "@dcloudio/vite-plugin-uni";

import PiniaAutoRefs from 'pinia-auto-refs'
import AutoImport from 'unplugin-auto-import/vite'

import {resolve} from 'node:path'

import Components from '@uni-helper/vite-plugin-uni-components'
import {WotResolver} from '@uni-helper/vite-plugin-uni-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        alias: {
            '@': resolve(__dirname, './src'),
        },
        extensions: ['.mjs', '.js', '.jsx', '.json', '.vue'],
    },
    build: {
        sourcemap: true,
    },
    plugins: [
        PiniaAutoRefs({
            storeDir: 'src/store',
        }),
        AutoImport({
            dts: 'src/auto-imports.d.ts',
            imports: [
                'vue',
                'uni-app',
                'pinia',
                {
                    '@/helper/pinia-auto-refs': ['useStore'],
                },
            ],
            exclude: ['createApp'],
            eslintrc: {
                enabled: true,
            },
        }),
        Components({
            resolvers: [WotResolver()]
        }),
        uni()
    ],
    server: {
        open: true, // 自动打开
        proxy: {
            '^/': {
                target: 'http://192.168.0.11:9527/', // 后端服务实际地址
                changeOrigin: true, // 开启代理
                rewrite: (path) => path.replace(/^\/api/, ''),
            },
        },
    },
});
